<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nih: sampling/distributions.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nih
   &#160;<span id="projectnumber">0.5</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('distributions_8h.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">sampling/distributions.h</div>  </div>
</div>
<div class="contents">
<a href="distributions_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2010-2011, NVIDIA Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00007"></a>00007 <span class="comment"> *   * Redistributions of source code must retain the above copyright</span>
<a name="l00008"></a>00008 <span class="comment"> *     notice, this list of conditions and the following disclaimer.</span>
<a name="l00009"></a>00009 <span class="comment"> *   * Redistributions in binary form must reproduce the above copyright</span>
<a name="l00010"></a>00010 <span class="comment"> *     notice, this list of conditions and the following disclaimer in the</span>
<a name="l00011"></a>00011 <span class="comment"> *     documentation and/or other materials provided with the distribution.</span>
<a name="l00012"></a>00012 <span class="comment"> *   * Neither the name of NVIDIA Corporation nor the</span>
<a name="l00013"></a>00013 <span class="comment"> *     names of its contributors may be used to endorse or promote products</span>
<a name="l00014"></a>00014 <span class="comment"> *     derived from this software without specific prior written permission.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span>
<a name="l00017"></a>00017 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<a name="l00018"></a>00018 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<a name="l00019"></a>00019 <span class="comment"> * DISCLAIMED. IN NO EVENT SHALL &lt;COPYRIGHT HOLDER&gt; BE LIABLE FOR ANY</span>
<a name="l00020"></a>00020 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<a name="l00021"></a>00021 <span class="comment"> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<a name="l00022"></a>00022 <span class="comment"> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<a name="l00023"></a>00023 <span class="comment"> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00024"></a>00024 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00025"></a>00025 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00026"></a>00026 <span class="comment"> */</span>
<a name="l00027"></a>00027 
<a name="l00032"></a>00032 <span class="preprocessor">#ifndef __NIH_DISTRIBUTIONS_H</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define __NIH_DISTRIBUTIONS_H</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;<a class="code" href="random_8h.html" title="Defines a random number generator class.">nih/sampling/random.h</a>&gt;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">namespace </span>nih {
<a name="l00038"></a>00038 
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Derived_type&gt;
<a name="l00051"></a><a class="code" href="structnih_1_1_base__distribution.html">00051</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>
<a name="l00052"></a>00052 {
<a name="l00056"></a>00056     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Generator&gt;
<a name="l00057"></a><a class="code" href="structnih_1_1_base__distribution.html#af5dfede8d6986295917e5ae7c3615cb2">00057</a>         <span class="keyword">inline</span> <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_base__distribution.html#af5dfede8d6986295917e5ae7c3615cb2">next</a>(Generator&amp; gen)<span class="keyword"> const</span>
<a name="l00058"></a>00058 <span class="keyword">        </span>{
<a name="l00059"></a>00059         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span>Derived_type*<span class="keyword">&gt;</span>(<span class="keyword">this</span>)-&gt;map( gen.next() );
<a name="l00060"></a>00060     }
<a name="l00061"></a>00061 };
<a name="l00062"></a>00062 
<a name="l00066"></a><a class="code" href="structnih_1_1_uniform__distribution.html">00066</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_uniform__distribution.html">Uniform_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Uniform_distribution&gt;
<a name="l00067"></a>00067 {
<a name="l00071"></a><a class="code" href="structnih_1_1_uniform__distribution.html#a789a6e0b4a63ed9141a7a40a19e5ab88">00071</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_uniform__distribution.html#a789a6e0b4a63ed9141a7a40a19e5ab88">Uniform_distribution</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> b) : m_b( b ) {}
<a name="l00072"></a>00072 
<a name="l00076"></a><a class="code" href="structnih_1_1_uniform__distribution.html#a8ead1bb77090d5fb7a5e17fbcfbc9f8a">00076</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_uniform__distribution.html#a8ead1bb77090d5fb7a5e17fbcfbc9f8a">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_b * (U*2.0f - 1.0f); }
<a name="l00077"></a>00077 
<a name="l00081"></a><a class="code" href="structnih_1_1_uniform__distribution.html#a99dc0a087755376979421e915055a8cb">00081</a>     <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_uniform__distribution.html#a99dc0a087755376979421e915055a8cb">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00082"></a>00082 <span class="keyword">    </span>{
<a name="l00083"></a>00083         <span class="keywordflow">return</span> (x &gt;= -m_b &amp;&amp; x &lt;= m_b) ? m_b * 2.0f : 0.0f;
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 <span class="keyword">private</span>:
<a name="l00087"></a>00087     <span class="keywordtype">float</span> m_b;
<a name="l00088"></a>00088 };
<a name="l00092"></a><a class="code" href="structnih_1_1_cosine__distribution.html">00092</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_cosine__distribution.html">Cosine_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Cosine_distribution&gt;
<a name="l00093"></a>00093 {
<a name="l00097"></a><a class="code" href="structnih_1_1_cosine__distribution.html#a9f6794396c7cee3e10d95d3d3f70a14e">00097</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_cosine__distribution.html#a9f6794396c7cee3e10d95d3d3f70a14e">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00098"></a>00098 <span class="keyword">    </span>{
<a name="l00099"></a>00099         <span class="keywordflow">return</span> asin( 0.5f * U ) * 2.0f / M_PIf;
<a name="l00100"></a>00100     }
<a name="l00104"></a><a class="code" href="structnih_1_1_cosine__distribution.html#a71542a12b020e6f3db6ab5d52c0725b9">00104</a>     <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_cosine__distribution.html#a71542a12b020e6f3db6ab5d52c0725b9">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00105"></a>00105 <span class="keyword">    </span>{
<a name="l00106"></a>00106         <span class="keywordflow">if</span> (x &gt;= -1.0f &amp;&amp; x &lt;= 1.0f)
<a name="l00107"></a>00107             <span class="keywordflow">return</span> M_PIf*0.25f * cosf( x * M_PIf*0.5f );
<a name="l00108"></a>00108         <span class="keywordflow">return</span> 0.0f;
<a name="l00109"></a>00109     }
<a name="l00110"></a>00110 };
<a name="l00114"></a><a class="code" href="structnih_1_1_pareto__distribution.html">00114</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_pareto__distribution.html">Pareto_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Pareto_distribution&gt;
<a name="l00115"></a>00115 {
<a name="l00120"></a><a class="code" href="structnih_1_1_pareto__distribution.html#aa60c9e6b328d61f27b1e2e86fe85f37c">00120</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_pareto__distribution.html#aa60c9e6b328d61f27b1e2e86fe85f37c">Pareto_distribution</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> a, <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="group__vectors.html#ga5809911d15c32de18955c59865379695">min</a>) : m_a( a ), m_inv_a( 1.0f / a ), m_min( min ) {}
<a name="l00121"></a>00121 
<a name="l00125"></a><a class="code" href="structnih_1_1_pareto__distribution.html#a08b43ee449861420eafe309c2257a9e0">00125</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_pareto__distribution.html#a08b43ee449861420eafe309c2257a9e0">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00126"></a>00126 <span class="keyword">    </span>{
<a name="l00127"></a>00127         <span class="keywordflow">return</span> U &lt; 0.5f ?
<a name="l00128"></a>00128              m_min / powf( (0.5f - U)*2.0f, m_inv_a ) :
<a name="l00129"></a>00129             -m_min / powf( (U - 0.5f)*2.0f, m_inv_a );
<a name="l00130"></a>00130     }
<a name="l00134"></a><a class="code" href="structnih_1_1_pareto__distribution.html#aeed562d580b3e12c5b73fca4f49a3426">00134</a>     <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_pareto__distribution.html#aeed562d580b3e12c5b73fca4f49a3426">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00135"></a>00135 <span class="keyword">    </span>{
<a name="l00136"></a>00136         <span class="keywordflow">if</span> (x &gt;= -m_min &amp;&amp; x &lt;= m_min)
<a name="l00137"></a>00137             <span class="keywordflow">return</span> 0.0f;
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <span class="keywordflow">return</span> 0.5f * m_a * powf( m_min, m_a ) / powf( fabsf(x), m_a + 1.0f );
<a name="l00140"></a>00140     }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 <span class="keyword">private</span>:
<a name="l00143"></a>00143     <span class="keywordtype">float</span> m_a;
<a name="l00144"></a>00144         <span class="keywordtype">float</span> m_inv_a;
<a name="l00145"></a>00145     <span class="keywordtype">float</span> m_min;
<a name="l00146"></a>00146 };
<a name="l00150"></a><a class="code" href="structnih_1_1_bounded__pareto__distribution.html">00150</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_bounded__pareto__distribution.html">Bounded_pareto_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Bounded_pareto_distribution&gt;
<a name="l00151"></a>00151 {
<a name="l00157"></a><a class="code" href="structnih_1_1_bounded__pareto__distribution.html#a9ca7eeb175f3f614b7f2d8a58001e8d7">00157</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_bounded__pareto__distribution.html#a9ca7eeb175f3f614b7f2d8a58001e8d7">Bounded_pareto_distribution</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> a, <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="group__vectors.html#ga5809911d15c32de18955c59865379695">min</a>, <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">max</a>) :
<a name="l00158"></a>00158         m_a( a ), m_inv_a( 1.0f / a ), m_min( min ), m_max( max ),
<a name="l00159"></a>00159         m_min_a( powf( m_min, m_a ) ),
<a name="l00160"></a>00160         m_max_a( powf( m_max, m_a ) ) {}
<a name="l00161"></a>00161 
<a name="l00165"></a><a class="code" href="structnih_1_1_bounded__pareto__distribution.html#ab7bcf61d38254eeb3b5898dfdf7b54e5">00165</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_bounded__pareto__distribution.html#ab7bcf61d38254eeb3b5898dfdf7b54e5">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00166"></a>00166 <span class="keyword">    </span>{
<a name="l00167"></a>00167         <span class="keywordflow">if</span> (U &lt; 0.5f)
<a name="l00168"></a>00168         {
<a name="l00169"></a>00169             <span class="keyword">const</span> <span class="keywordtype">float</span> u = (0.5f - U)*2.0f;
<a name="l00170"></a>00170             <span class="keywordflow">return</span> powf( -(u * m_max_a - u * m_min_a - m_max_a) / (m_max_a*m_min_a), -m_inv_a);
<a name="l00171"></a>00171         }
<a name="l00172"></a>00172         <span class="keywordflow">else</span>
<a name="l00173"></a>00173         {
<a name="l00174"></a>00174             <span class="keyword">const</span> <span class="keywordtype">float</span> u = (U - 0.5f)*2.0f;
<a name="l00175"></a>00175             <span class="keywordflow">return</span> -powf( -(u * m_max_a - u * m_min_a - m_max_a) / (m_max_a*m_min_a), -m_inv_a);
<a name="l00176"></a>00176         }
<a name="l00177"></a>00177     }
<a name="l00181"></a><a class="code" href="structnih_1_1_bounded__pareto__distribution.html#aecd459146a179522bcae18e18876ba9a">00181</a>     <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_bounded__pareto__distribution.html#aecd459146a179522bcae18e18876ba9a">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00182"></a>00182 <span class="keyword">    </span>{
<a name="l00183"></a>00183         <span class="keywordflow">if</span> (x &gt;= -m_min &amp;&amp; x &lt;= m_min)
<a name="l00184"></a>00184             <span class="keywordflow">return</span> 0.0f;
<a name="l00185"></a>00185         <span class="keywordflow">if</span> (x &lt;= -m_max || x &gt;= m_max)
<a name="l00186"></a>00186             <span class="keywordflow">return</span> 0.0f;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         <span class="keywordflow">return</span> 0.5f * m_a * m_min_a * powf( fabsf(x), -m_a - 1.0f ) / (1.0f - m_min_a / m_max_a);
<a name="l00189"></a>00189     }
<a name="l00190"></a>00190 
<a name="l00191"></a>00191 <span class="keyword">private</span>:
<a name="l00192"></a>00192     <span class="keywordtype">float</span> m_a;
<a name="l00193"></a>00193         <span class="keywordtype">float</span> m_inv_a;
<a name="l00194"></a>00194     <span class="keywordtype">float</span> m_min;
<a name="l00195"></a>00195     <span class="keywordtype">float</span> m_max;
<a name="l00196"></a>00196     <span class="keywordtype">float</span> m_min_a;
<a name="l00197"></a>00197     <span class="keywordtype">float</span> m_max_a;
<a name="l00198"></a>00198 };
<a name="l00202"></a><a class="code" href="structnih_1_1_bounded__exponential.html">00202</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_bounded__exponential.html">Bounded_exponential</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Bounded_exponential&gt;
<a name="l00203"></a>00203 {
<a name="l00207"></a><a class="code" href="structnih_1_1_bounded__exponential.html#adf12b05179b24155ef3b581d9ea98cd5">00207</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_bounded__exponential.html#adf12b05179b24155ef3b581d9ea98cd5">Bounded_exponential</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> b) :
<a name="l00208"></a>00208                 m_s1( b / 16.0f ),
<a name="l00209"></a>00209                 m_s2( b ),
<a name="l00210"></a>00210                 m_ln( -log(m_s2/m_s1) ) {}
<a name="l00211"></a>00211 
<a name="l00215"></a><a class="code" href="structnih_1_1_bounded__exponential.html#ac7a194ec2c5be6602a874ee2ca124c48">00215</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_bounded__exponential.html#ac7a194ec2c5be6602a874ee2ca124c48">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00216"></a>00216 <span class="keyword">        </span>{
<a name="l00217"></a>00217                 <span class="keywordflow">return</span> U &lt; 0.5f ?
<a name="l00218"></a>00218                         +m_s2 * exp( m_ln*(0.5f - U)*2.0f ) :
<a name="l00219"></a>00219                         -m_s2 * exp( m_ln*(U - 0.5f)*2.0f );
<a name="l00220"></a>00220         }
<a name="l00221"></a>00221 
<a name="l00222"></a>00222 <span class="keyword">private</span>:
<a name="l00223"></a>00223     <span class="keywordtype">float</span> m_s1;
<a name="l00224"></a>00224         <span class="keywordtype">float</span> m_s2;
<a name="l00225"></a>00225         <span class="keywordtype">float</span> m_ln;
<a name="l00226"></a>00226 };
<a name="l00230"></a><a class="code" href="structnih_1_1_cauchy__distribution.html">00230</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_cauchy__distribution.html">Cauchy_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Cauchy_distribution&gt;
<a name="l00231"></a>00231 {
<a name="l00235"></a><a class="code" href="structnih_1_1_cauchy__distribution.html#a889519a1beeec6bbc12c261c1753ed44">00235</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_cauchy__distribution.html#a889519a1beeec6bbc12c261c1753ed44">Cauchy_distribution</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> gamma) :
<a name="l00236"></a>00236                 m_gamma( gamma ) {}
<a name="l00237"></a>00237 
<a name="l00241"></a><a class="code" href="structnih_1_1_cauchy__distribution.html#a88c77398b5079e0cc9a2fdfdabb8f026">00241</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_cauchy__distribution.html#a88c77398b5079e0cc9a2fdfdabb8f026">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00242"></a>00242 <span class="keyword">        </span>{
<a name="l00243"></a>00243                 <span class="keywordflow">return</span> m_gamma * tanf( <span class="keywordtype">float</span>(M_PI) * (U - 0.5f) );
<a name="l00244"></a>00244         }
<a name="l00248"></a><a class="code" href="structnih_1_1_cauchy__distribution.html#abd5eace5e25609fdaf0d282335be0581">00248</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_cauchy__distribution.html#abd5eace5e25609fdaf0d282335be0581">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00249"></a>00249 <span class="keyword">        </span>{
<a name="l00250"></a>00250                 <span class="keywordflow">return</span> (m_gamma / (x*x + m_gamma*m_gamma)) / float(M_PI);
<a name="l00251"></a>00251         }
<a name="l00252"></a>00252 
<a name="l00253"></a>00253 <span class="keyword">private</span>:
<a name="l00254"></a>00254     <span class="keywordtype">float</span> m_gamma;
<a name="l00255"></a>00255 };
<a name="l00259"></a><a class="code" href="structnih_1_1_exponential__distribution.html">00259</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_exponential__distribution.html">Exponential_distribution</a> : <a class="code" href="structnih_1_1_base__distribution.html">Base_distribution</a>&lt;Exponential_distribution&gt;
<a name="l00260"></a>00260 {
<a name="l00264"></a><a class="code" href="structnih_1_1_exponential__distribution.html#a43395dcc56fadd2010a6eeae8cd8ba55">00264</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_exponential__distribution.html#a43395dcc56fadd2010a6eeae8cd8ba55">Exponential_distribution</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> lambda) :
<a name="l00265"></a>00265                 m_lambda( lambda ) {}
<a name="l00266"></a>00266 
<a name="l00270"></a><a class="code" href="structnih_1_1_exponential__distribution.html#ab6f68de1b8219158dccf8a3f353bf8b7">00270</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_exponential__distribution.html#ab6f68de1b8219158dccf8a3f353bf8b7">map</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> U)<span class="keyword"> const</span>
<a name="l00271"></a>00271 <span class="keyword">        </span>{
<a name="l00272"></a>00272                 <span class="keyword">const</span> <span class="keywordtype">float</span> eps = 1.0e-5f;
<a name="l00273"></a>00273                 <span class="keywordflow">return</span> U &lt; 0.5f ?
<a name="l00274"></a>00274                         -logf( <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">std::max</a>( (0.5f - U)*2.0f, eps ) ) / m_lambda :
<a name="l00275"></a>00275                          logf( <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">std::max</a>( (U - 0.5f)*2.0f, eps ) ) / m_lambda;
<a name="l00276"></a>00276         }
<a name="l00280"></a><a class="code" href="structnih_1_1_exponential__distribution.html#af8373dc96763a892b59e078986d68351">00280</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_exponential__distribution.html#af8373dc96763a892b59e078986d68351">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00281"></a>00281 <span class="keyword">        </span>{
<a name="l00282"></a>00282                 <span class="keywordflow">return</span> 0.5f * m_lambda * expf( -m_lambda * fabsf(x) );
<a name="l00283"></a>00283         }
<a name="l00284"></a>00284 
<a name="l00285"></a>00285 <span class="keyword">private</span>:
<a name="l00286"></a>00286     <span class="keywordtype">float</span> m_lambda;
<a name="l00287"></a>00287 };
<a name="l00291"></a><a class="code" href="structnih_1_1_gaussian__distribution__2d.html">00291</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_gaussian__distribution__2d.html">Gaussian_distribution_2d</a>
<a name="l00292"></a>00292 {
<a name="l00296"></a><a class="code" href="structnih_1_1_gaussian__distribution__2d.html#a462ba9099ada62297fc204229a112ba2">00296</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_gaussian__distribution__2d.html#a462ba9099ada62297fc204229a112ba2">Gaussian_distribution_2d</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> sigma) :
<a name="l00297"></a>00297                 m_sigma( sigma ) {}
<a name="l00298"></a>00298 
<a name="l00302"></a><a class="code" href="structnih_1_1_gaussian__distribution__2d.html#a74667f95aefadee5ea45d2c7674fa17d">00302</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <a class="code" href="structnih_1_1_vector.html">Vector2f</a> <a class="code" href="structnih_1_1_gaussian__distribution__2d.html#a74667f95aefadee5ea45d2c7674fa17d">map</a>(<span class="keyword">const</span> <a class="code" href="structnih_1_1_vector.html">Vector2f</a> uv)<span class="keyword"> const</span>
<a name="l00303"></a>00303 <span class="keyword">        </span>{
<a name="l00304"></a>00304                 <span class="keyword">const</span> <span class="keywordtype">float</span> eps = 1.0e-5f;
<a name="l00305"></a>00305                 <span class="keyword">const</span> <span class="keywordtype">float</span> r = m_sigma * sqrtf( - 2.0f * logf( <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">std::max</a>( uv[0], eps ) ) );
<a name="l00306"></a>00306                 <span class="keywordflow">return</span> <a class="code" href="structnih_1_1_vector.html">Vector2f</a>(
<a name="l00307"></a>00307                         r * cosf( 2.0f * <span class="keywordtype">float</span>(M_PI) * uv[1] ),
<a name="l00308"></a>00308                         r * sinf( 2.0f * <span class="keywordtype">float</span>(M_PI) * uv[1] ) );
<a name="l00309"></a>00309         }
<a name="l00310"></a>00310 
<a name="l00311"></a>00311 <span class="keyword">private</span>:
<a name="l00312"></a>00312         <span class="keywordtype">float</span> m_sigma;
<a name="l00313"></a>00313 };
<a name="l00314"></a>00314 
<a name="l00318"></a>00318 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Generator, <span class="keyword">typename</span> Distribution&gt;
<a name="l00319"></a><a class="code" href="structnih_1_1_transform__generator.html">00319</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_transform__generator.html">Transform_generator</a>
<a name="l00320"></a>00320 {
<a name="l00325"></a><a class="code" href="structnih_1_1_transform__generator.html#a2eb6f406cccc2183d8925e850ac5138d">00325</a>     NIH_HOST_DEVICE <a class="code" href="structnih_1_1_transform__generator.html#a2eb6f406cccc2183d8925e850ac5138d">Transform_generator</a>(Generator&amp; gen, <span class="keyword">const</span> Distribution&amp; dist) : m_gen( gen ), m_dist( dist ) {}
<a name="l00326"></a>00326 
<a name="l00329"></a><a class="code" href="structnih_1_1_transform__generator.html#a707e7a74d89d556a64d8894bef3f2143">00329</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_transform__generator.html#a707e7a74d89d556a64d8894bef3f2143">next</a>()<span class="keyword"> const</span>
<a name="l00330"></a>00330 <span class="keyword">        </span>{
<a name="l00331"></a>00331         <span class="keywordflow">return</span> m_dist.map( m_gen.next() );
<a name="l00332"></a>00332     }
<a name="l00336"></a><a class="code" href="structnih_1_1_transform__generator.html#a42b361037ac1879ae4e81f3757b5ce02">00336</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_transform__generator.html#a42b361037ac1879ae4e81f3757b5ce02">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00337"></a>00337 <span class="keyword">        </span>{
<a name="l00338"></a>00338         <span class="keywordflow">return</span> m_dist.density( x );
<a name="l00339"></a>00339     }
<a name="l00340"></a>00340 
<a name="l00341"></a>00341     Generator&amp;   m_gen;
<a name="l00342"></a>00342     Distribution m_dist;
<a name="l00343"></a>00343 };
<a name="l00344"></a>00344 
<a name="l00349"></a><a class="code" href="structnih_1_1_gaussian__generator.html">00349</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_gaussian__generator.html">Gaussian_generator</a>
<a name="l00350"></a>00350 {
<a name="l00354"></a><a class="code" href="structnih_1_1_gaussian__generator.html#a9b55397f76ed303fd87af98398e8683d">00354</a>         NIH_HOST_DEVICE <a class="code" href="structnih_1_1_gaussian__generator.html#a9b55397f76ed303fd87af98398e8683d">Gaussian_generator</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> sigma) :
<a name="l00355"></a>00355                 m_sigma( sigma ),
<a name="l00356"></a>00356                 m_cached( false ) {}
<a name="l00357"></a>00357 
<a name="l00361"></a>00361     <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Generator&gt;
<a name="l00362"></a><a class="code" href="structnih_1_1_gaussian__generator.html#ad30a0b8d00bfdb7729a14387b68779f2">00362</a>         <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_gaussian__generator.html#ad30a0b8d00bfdb7729a14387b68779f2">next</a>(Generator&amp; random)
<a name="l00363"></a>00363         {
<a name="l00364"></a>00364                 <span class="keywordflow">if</span> (m_cached)
<a name="l00365"></a>00365                 {
<a name="l00366"></a>00366                         m_cached = <span class="keyword">false</span>;
<a name="l00367"></a>00367                         <span class="keywordflow">return</span> m_cache;
<a name="l00368"></a>00368                 }
<a name="l00369"></a>00369 
<a name="l00370"></a>00370                 <span class="keyword">const</span> <a class="code" href="structnih_1_1_vector.html">Vector2f</a> uv( random.next(), random.next() );
<a name="l00371"></a>00371                 <span class="keyword">const</span> <span class="keywordtype">float</span> eps = 1.0e-5f;
<a name="l00372"></a>00372                 <span class="keyword">const</span> <span class="keywordtype">float</span> r = m_sigma * sqrtf( - 2.0f * logf( <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">std::max</a>( uv[0], eps ) ) );
<a name="l00373"></a>00373                 <span class="keyword">const</span> <span class="keywordtype">float</span> y0 = r * cosf( 2.0f * <span class="keywordtype">float</span>(M_PI) * uv[1] );
<a name="l00374"></a>00374                 <span class="keyword">const</span> <span class="keywordtype">float</span> y1 = r * sinf( 2.0f * <span class="keywordtype">float</span>(M_PI) * uv[1] );
<a name="l00375"></a>00375 
<a name="l00376"></a>00376                 m_cache  = y1;
<a name="l00377"></a>00377                 m_cached = <span class="keyword">true</span>;
<a name="l00378"></a>00378                 <span class="keywordflow">return</span> y0;
<a name="l00379"></a>00379         }
<a name="l00383"></a><a class="code" href="structnih_1_1_gaussian__generator.html#ad610749fa56473e8ffa9c7a99fdd14dd">00383</a>     <span class="keyword">inline</span> NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="structnih_1_1_gaussian__generator.html#ad610749fa56473e8ffa9c7a99fdd14dd">density</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> x)<span class="keyword"> const</span>
<a name="l00384"></a>00384 <span class="keyword">    </span>{
<a name="l00385"></a>00385         <span class="keyword">const</span> <span class="keywordtype">float</span> SQRT_TWO_PI = sqrtf(2.0f * M_PIf);
<a name="l00386"></a>00386         <span class="keywordflow">return</span> expf( -x*x/(2.0f*m_sigma*m_sigma) ) / (SQRT_TWO_PI*m_sigma);
<a name="l00387"></a>00387     }
<a name="l00388"></a>00388 
<a name="l00389"></a>00389 <span class="keyword">private</span>:
<a name="l00390"></a>00390     <span class="keywordtype">float</span>  m_sigma;
<a name="l00391"></a>00391         <span class="keywordtype">float</span>  m_cache;
<a name="l00392"></a>00392         <span class="keywordtype">bool</span>   m_cached;
<a name="l00393"></a>00393 };
<a name="l00394"></a>00394 
<a name="l00398"></a>00398 } <span class="comment">// namespace nih</span>
<a name="l00399"></a>00399 
<a name="l00400"></a>00400 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="distributions_8h.html">distributions.h</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">Generated on Thu Dec 15 2011 11:56:19 for nih by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
